<%@ tag pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="promotion" uri="http://com.primus.promotion/tag/core" %>
<%@ taglib prefix="pbase" tagdir="/WEB-INF/tags/base" %>
<%@ attribute name="promotionId" required="true" type="java.lang.Long" %>
<%@ taglib prefix="primus" tagdir="/WEB-INF/tags" %>

<pbase:row layout="single">
    <label class="col-sm-2 control-label no-padding-right">设置降价规则</label>
    <div class="col-sm-10 form-group">
        <div class="col-xs-12">
            <div class="row col-xs-12"><span id="_icon_plus_rule" class="label"><i
                    class="ace-icon glyphicon glyphicon-plus"></i></span></div>
            <div class="row col-xs-12">
                <table id="_cut_table" class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>时间段</th>
                        <th>价格</th>
                        <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</pbase:row>

<script>
    $(function () {

        function init_date_time_picker() {
            $('.time').each(function () {
                $(this).datetimepicker({
                    showClear: true,
                    format: "yyyy-mm-dd hh:ii:ss"
                })
            });
        }

        var $table_body = $('#_cut_table').find('tbody');

        $.ajax({
            cache: true,
            async: false,
            url: 'management/cutPriceSalePromotion/rules.do?id=${promotionId}',
            type: 'get',
            dataType: 'json'
        }).success(function (data) {
            var append_html = [];
            for (var d in data) {
                append_html.push('<tr>');
                append_html.push('<td class="timeSection"><input type="text" class="time" value="' + data[d].startTime + '"/>&nbsp;&nbsp; - &nbsp;&nbsp;' + '<input class="time" type="text" value="' + data[d].endTime + '"/></td>');
                append_html.push('<td class="price"><input type="number" value="' + data[d].salePrice + '"/></td>');
                append_html.push('<td><span class="btn btn-xs btn-info rule_remove"><i class="ace-icon glyphicon glyphicon-remove"></i></span></td>')
                append_html.push('</tr>');
            }
            $table_body.append(append_html.join("\n"));
//            init_date_time_picker();
        });

        $('#_icon_plus_rule').click(function () {
            var append_html = [];
            append_html.push('<tr>');
            append_html.push('<td class="timeSection"><input type="text" class="time"/>&nbsp;&nbsp; - &nbsp;&nbsp;' + '<input type="text" class="time"/></td>');
            append_html.push('<td class="price"><input type="number"/></td>');
            append_html.push('<td><span class="btn btn-xs btn-info rule_remove"><i class="ace-icon glyphicon glyphicon-remove"></i></span></td>')
            append_html.push('</tr>');
            $table_body.append(append_html.join("\n"));
//            init_date_time_picker();
        });

        $table_body.on('click', '.rule_remove', function () {
            $(this).parents("tr").remove();
        });
    });
</script>

